//import router from 'umi/router';

import React from 'react';
import { connect } from 'dva';
//import Link from 'umi/link'
import { Table, Button } from 'antd';

//const linePath = '/AccountStock/Stock';
//const formPath = '/AccountStock/StockForm';

@connect(({
  accountStock
}) => ({
  accountStock
}))
class List extends React.Component {
  state = {
  }

  treeview = [
      { title: '日期', dataIndex: 'date', },
      { title: '状态', dataIndex: 'stock_id.state', },
      { title: '产品类型', dataIndex: 'product_type', },
      { title: '出入库方向', dataIndex: 'direction', },
      { title: '出库方式', dataIndex: 'move_type', },
      { title: '账簿', dataIndex: 'journal_id.name', },
      { title: '科目', dataIndex: 'account_id.name', },
      { title: '对方科目', dataIndex: 'opp_account_id.name', },
      { title: '产品', dataIndex: 'product_id.name', },
      { title: '金额', dataIndex: 'amount', },
      { title: '数量', dataIndex: 'quantity', },
      { title: '单价', dataIndex: 'price', },


  ]

  async componentDidMount() {
    const { dispatch } = this.props;

    await dispatch({
      type: 'accountStock/search',
      payload: {domain:[['move_type','=','open']], },

    });


  }


  async post_open() {
    const { accountStock: { ids } } = this.props;
    const { dispatch } = this.props;

    console.log(ids)

    await dispatch({
        type: 'accountStock/post_open',
        payload:  { id: ids  }
    });

  }


  render() {
    const { accountStock: { recordsList } } = this.props;
    const line_ids = recordsList.reduce((acc,cur)=>{
      acc = [...acc, ...cur.line_ids ]
      return acc
    },[])

    return (
      <div>
        <div>
          期初数导入，创建  balance.line
        </div>
        <Button onClick={()=>this.post_open()}>导入到财务期初</Button>

        <Table columns={this.treeview} dataSource={line_ids} rowKey="id" />


      </div>
    );
  }
}

export default List;





